package 头条;

import java.util.Scanner;

public class 头条机试2暴力方法 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = new Tools().getRandomNum(1, 100);
            }

            long beg = System.currentTimeMillis();
            func(a, n);
            long end = System.currentTimeMillis();
            System.out.println(end - beg);
        }
        sc.close();
    }

    //时间O(N^3) 空间O(1)
    private static void func(int[] a, int n) {
        long max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                long tmp = calc(a, i, j);
                max = Math.max(max, tmp);
            }
        }
        System.out.println(max);
    }

    private static long calc(int[] a, int i, int j) {
        int min = Integer.MAX_VALUE;
        long sum = 0;
        for (int k = i; k <= j; k++) {
            min = Math.min(min, a[k]);
            sum += a[k];
        }
        return min * sum;
    }

}
